package com.mz.ozy.adapter;

import android.text.TextUtils;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mz.ozy.R;
import com.mz.ozy.bean.MyBookBean;
import com.mz.ozy.utils.ScreenUtil;
import com.mz.ozy.utils.glideUtils.GlideUtils;

import java.util.List;

/**
 * @author lifeStyle on 2020/4/3 0003.
 */
public class CardBookListAdapter extends BaseQuickAdapter<MyBookBean.PageBean.PageItemsBean, BaseViewHolder> {

    public CardBookListAdapter(List<MyBookBean.PageBean.PageItemsBean> data) {
        super(R.layout.item_my_book, data);

    }

    @Override
    protected void convert(BaseViewHolder helper, MyBookBean.PageBean.PageItemsBean item) {

        helper.setText(R.id.tv_strategy_title, item.getTitle());
        helper.setText(R.id.tv_strategy_content, item.getIntroduction());
        helper.setText(R.id.tv_strategy_readnum, item.getBrowseNum() + "");
        helper.setText(R.id.tv_strategy_time, item.getRecommendDate());
        helper.setText(R.id.tv_strategy_likenum, item.getCollNum());
        if (TextUtils.isEmpty(item.getImg1())) {
            GlideUtils.loadImg(mContext, helper.getView(R.id.iv_item_find_dynamics_user), R.mipmap.default_strategy_rect_banner);
        } else {
            GlideUtils.loadBackImg(mContext, helper.getView(R.id.iv_item_find_dynamics_user), item.getImg1(), R.mipmap.default_strategy_rect_banner);
        }

        View rootView = helper.getView(R.id.item_root_view);
        int adapterPosition = helper.getAdapterPosition() - getHeaderLayoutCount();
        if (adapterPosition == getData().size() - 1) {
            helper.setGone(R.id.view_strategy_divider, false);
            rootView.setPadding(rootView.getPaddingLeft(), rootView.getPaddingTop(), rootView.getPaddingRight(), ScreenUtil.dip2px(mContext, 20));
        } else {
            helper.setVisible(R.id.view_strategy_divider, true);
            rootView.setPadding(rootView.getPaddingLeft(), rootView.getPaddingTop(), rootView.getPaddingRight(), ScreenUtil.dip2px(mContext, 15));
        }


    }

}
